package com.noble.meether.chat.ui.agora.act.video;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.noble.glamour.bean.center.user.detail.UserDetail;
import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.glamour.module.util.UIShow;
import com.noble.library.utils.NoDoubleClickListener;
import com.noble.library.view.base.BasePanel;
import com.noble.meether.R;
import com.noble.meether.chat.ui.agora.RtcUIShow;
import com.noble.meether.chat.ui.agora.dialog.listener.GiftSendListener;
import com.noble.meether.chat.ui.agora.util.RtcJointChannel;

/**
 * 音视频: 底部功能键
 */
public class ChatFootPanel extends BasePanel {
    private LinearLayout container;
    private ImageView chat_beautify;  // 美颜按钮
    private RtcChatInputPanel inputPanel;

    private GiftSendListener sendListener;

    public ChatFootPanel(Context context) {
        super(context);
        setContentView(R.layout.chat_foot_panel);
        if (context instanceof GiftSendListener)
            sendListener = (GiftSendListener) context;
        initView();
    }

    private void initView() {
        UserDetail userDetail = ModuleMgr.getCenterMgr().getMyInfo();
        if (userDetail.isMan()) {
            ImageView chat_gift = (ImageView) findViewById(R.id.chat_gift);
            ImageView chat_recharge = (ImageView) findViewById(R.id.chat_recharge);
            chat_gift.setOnClickListener(listener);
            chat_recharge.setOnClickListener(listener);
            chat_gift.setVisibility(View.VISIBLE);
            chat_recharge.setVisibility(View.VISIBLE);
        }

        chat_beautify = (ImageView) findViewById(R.id.chat_beautify);
        chat_beautify.setOnClickListener(listener);
        findViewById(R.id.chat_input).setOnClickListener(listener);
        findViewById(R.id.btn_close).setOnClickListener(listener);
        container = (LinearLayout) findViewById(R.id.chat_input_panel);
        inputPanel = new RtcChatInputPanel(getContext());
        container.addView(inputPanel.getContentView());
        inputPanel.setInputPanelListener(v -> refreshLayout());
    }

    public void beautyHidden() {
        if (chat_beautify != null)
            chat_beautify.setVisibility(View.GONE);
    }

    public void moveInputPanel(int length) {
        container.setTranslationY(length);
    }

    /**
     * 更新弹框布局
     */
    public void refreshLayout() {
        container.setVisibility(View.GONE);
        inputPanel.refresh(View.GONE);
    }

    private NoDoubleClickListener listener = new NoDoubleClickListener() {
        @Override
        public void onNoDoubleClick(View v) {
            switch (v.getId()) {
                case R.id.chat_input:// 发送文字
                    container.setVisibility(View.VISIBLE);
                    inputPanel.refresh(View.VISIBLE);
                    break;
                case R.id.chat_gift:// 送礼
                    RtcUIShow.showRtcBottomGiftDlg(getContext(), ModuleMgr.getRtcEnginMgr().getEngineConfig().mOtherId, true, sendListener);
                    break;
                case R.id.chat_recharge:// 充值
                    UIShow.showGoodsDiamondBottomDlg(getContext());
                    break;
                case R.id.btn_close:
                    RtcJointChannel.getInstance().stopChat();
                    break;

                case R.id.chat_beautify:
                    ModuleMgr.getRtcEnginMgr().switchBeauty();
                    break;
            }
        }
    };
}